package com.flyoil.petromp.adapter.adapter_me;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.BaseRecyAdapter;
import com.flyoil.petromp.entity.entity_me.MyMessageEntity;

/**
 * Created by songzhiiyn on 2017/10/9.
 * 我的消息的适配器
 */

public class ItemMessageAdapter extends BaseRecyAdapter<ItemMessageAdapter.ViewHolder, MyMessageEntity.DataBean.ListBean> {

    public ItemMessageAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ViewHolder viewHolder = new ViewHolder(mInflater.inflate(R.layout.item_my_message_adapter, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final MyMessageEntity.DataBean.ListBean entity = data.get(position);
        if (entity.isCanSelectck()) {
            if (entity.isSelected()) {
                viewHolder.img_status.setImageResource(R.mipmap.checkbox_true_icon);
            } else {
                viewHolder.img_status.setImageResource(R.mipmap.checkbox_false_icon);
            }

        } else {
            viewHolder.img_status.setImageResource(R.mipmap.back_right_icon);
        }
        if (entity.isIsRead() == false) {
            viewHolder.img_icon.setVisibility(View.VISIBLE);
        } else {
            viewHolder.img_icon.setVisibility(View.INVISIBLE);
        }
        viewHolder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.Onclick(position, entity);
                }
            }
        });
        viewHolder.tv_title.setText(entity.getMessageDetail());
    }


    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_title;
        private TextView tv_time;
        private ImageView img_icon;
        private ImageView img_status;
        private LinearLayout line;

        public ViewHolder(View itemView) {
            super(itemView);
            line = itemView.findViewById(R.id.line_item_my_message_adapter_layout);
            tv_title = itemView.findViewById(R.id.tv_item_message_adapter_title);
            tv_time = itemView.findViewById(R.id.tv_item_message_adapter_time);
            img_icon = itemView.findViewById(R.id.img_item_message_adapter_icon);
            img_status = itemView.findViewById(R.id.img_item_message_adapter_status);
        }
    }
}
